package com.cards_game.simple_ddz.common;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;

import com.cards_game.simple_ddz.constants.CommonConstants;

/**
 * 所有重要容器初始化
 * 
 * @author 郭国辉 2016年3月28日 上午10:32:35
 */
public class AllPrimaryContainer {

	private static AllPrimaryContainer allPrimaryContainer = new AllPrimaryContainer();
	
	/**
	 * 构造器私有，保证单例 初始化时，容器中放入固定个数的房间对象， 房间类为包访问权限， 整个项目只允许存在这些房间， 不允许再添加
	 */
	private AllPrimaryContainer() {
		if(playerRoomMap==null){
			playerRoomMap=new ConcurrentHashMap<Integer, RoomBean>(CommonConstants.ROOM_TOTAL*3);
		}
		if(allRoomMap==null){
			allRoomMap=new ConcurrentHashMap<Integer, RoomBean>(CommonConstants.ROOM_TOTAL);
		}
		if(notFullRooms==null){
			notFullRooms=new ConcurrentSkipListSet<>();
		}
		for (int i = 0; i < CommonConstants.ROOM_TOTAL; i++) {
			RoomBean rb = new RoomBean();
			rb.setId(i);
			allRoomMap.put(i, rb);
			notFullRooms.add(rb);
		}
	}

	public static AllPrimaryContainer getAllPrimaryContainer() {
		return allPrimaryContainer;
	}

	// 玩家-房间容器
	private volatile ConcurrentHashMap<Integer, RoomBean> playerRoomMap = null;
	// 所有房间容器
	private volatile ConcurrentHashMap<Integer, RoomBean> allRoomMap = null;
	// 未满房间容器
	private volatile ConcurrentSkipListSet<RoomBean> notFullRooms = null;

	public ConcurrentHashMap<Integer, RoomBean> getAllRoomMap() {
		return allRoomMap;
	}

	public ConcurrentSkipListSet<RoomBean> getNotFullRooms() {
		return notFullRooms;
	}

	public ConcurrentHashMap<Integer, RoomBean> getPlayerRoomMap() {
		return playerRoomMap;
	}
}
